package com.leetcode.weekly.contest.no282th;

import java.util.Arrays;

/**
 * @author 覃国强
 * @date 2022-02-27 10:35
 */
public class A02_使两字符串互为字母异位词的最少步骤数 {

  public static void main(String[] args) {
    Solution solution = new Solution();
    String s = "cotxazilut";
    String t = "nahrrmcchxwrieqqdwdpneitkxgnt";
    int minSteps = solution.minSteps(s, t);
    System.out.println(minSteps);
  }

  static
  class Solution {
    public int minSteps(String s, String t) {
      char[] sChars = s.toCharArray();
      char[] tChars = t.toCharArray();

      Arrays.sort(sChars);
      Arrays.sort(tChars);

      int answer = 0;
      int i = 0;
      int j = 0;
      while (i < sChars.length || j < tChars.length) {
        if (i == sChars.length) {
          ++j;
          ++answer;
        } else if (j == tChars.length) {
          ++i;
          ++answer;
        } else if (sChars[i] == tChars[j]) {
          ++i;
          ++j;
        } else if (sChars[i] < tChars[j]) {
          ++i;
          ++answer;
        } else {
          ++j;
          ++answer;
        }
      }

      return answer;
    }
  }

}
